#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {

        //使用二分法
        //先求开始位置，再求结束位置
        int left = 0;
        int right = nums.size()-1;
        int leftIndex = -1;
        int rightIndex = -1;
        while(left<=right){
            int mid = (left+right)>>1;
            if(nums[mid]<target){
                left = mid+1;
            }
            else if(nums[mid]>target){
                right = mid -1;
            }
            else{
                leftIndex = mid;
                right = mid-1;
            }
        }
        left = 0;
        right = nums.size()-1;
        while(left<=right){
            int mid = (left+right)>>1;
            if(nums[mid]<target){
                left = mid+1;
            }
            else if(nums[mid]>target){
                right = mid -1;
            }
            else{
                rightIndex = mid;
                left = mid+1;
            }
        }

        return {leftIndex,rightIndex};  
    }
};

int main(){
    Solution S;
    vector<int> nums = {5,7,7,8,8,10};
    vector<int> T = S.searchRange(nums,6);
    return 0;
}